<template>
    <div class="box"></div>
    <div>
        <van-field label="商户姓名" v-if="detail.customerName"  v-model="detail.customerName" readonly/>
        <van-field label="商户编号" v-if="detail.customerNo" v-model="detail.customerNo" readonly/>
        <van-field label="分享代理商编号" v-if="detail.shareAgentNo" v-model="detail.shareAgentNo" readonly/>
        <van-field label="分享代理商名称" v-if="detail.shareAgentName" v-model="detail.shareAgentName" readonly/>
        <van-field label="采购代理商编号" v-if="detail.agentNo" v-model="detail.agentNo" readonly/>
        <van-field label="采购代理商名称" v-if="detail.agentName" v-model="detail.agentName" readonly/>
        <van-field label="支付时间" v-if="detail.payTime" v-model="detail.payTime" readonly/>
        <van-field label="支付金额" v-if="detail.payAmount" v-model="detail.payAmount" readonly/>
        <van-field label="支付方式" v-if="detail.payWay" v-model="detail.payWay" readonly/>
        <van-field label="支付订单号" v-if="detail.flowId" v-model="detail.flowId" readonly/>
        <van-field label="TUSN"  v-if="detail.tusn" v-model="detail.tusn" readonly/>
        <van-field label="posSn" v-if="detail.posSn" v-model="detail.posSn" readonly/>
        <van-field label="交易流水号" v-if="detail.flowId" v-model="detail.flowId" readonly/>
        <van-field label="类型" v-if="detail.payTypeName" v-model="detail.payTypeName" readonly/>
        <van-field label="交易时间" v-if="detail.createTime" v-model="detail.createTime" readonly/>
        <van-field label="交易金额" v-if="detail.amount" v-model="detail.amount" readonly/>
        <van-field label="交易手续费" v-if="detail.custFeeAmount" v-model="detail.custFeeAmount" readonly/>
    </div>
</template>

<script>
import {
    findProfitDetailById,
    findActivateBackDetailById,
    findTjProfitDetailById,
    findActivateBackDetailByIdTwo
} from '@/api/agent'

export default {
    data() {
        return {
            detail: {}
        }
    },
    created() {
        console.log(this.$route.query.id,this.$route.query.backid,this.$route.query.tjid ,'22222222');
        if (this.$route.query.id) {
            findProfitDetailById({ flowId: this.$route.query.id }).then(res => {
                const { code, message, object } = res
                if (code == 200) {
                    object.createTime = this.parseTime(object.createTime)
                    this.detail = object
                    console.log(this.detail,'this.detail1');
                }
            })
        }
        if (this.$route.query.backid) {
            if(this.$route.query.type === 'yingkeBack'){
                findActivateBackDetailByIdTwo({ id: this.$route.query.backid,type: this.$route.query.type }).then(res => {
                    const { code, message, object } = res
                    if (code == 200) {
                        if (object.createTime) {
                            object.createTime = this.parseTime(object.createTime)
                        }
                        if (object.payTime) {
                            object.payTime = this.parseTime(object.payTime)
                        }
                        if (object.payWay === 'ZFB') {
                            object.payWay = '支付宝'
                        }
                        if (object.payWay === 'WX') {
                            object.payWay = '微信'
                        }
                        this.detail = object
                    }
                })
            }else{
                findActivateBackDetailById({ id: this.$route.query.backid }).then(res => {
                    const { code, message, object } = res
                    if (code == 200) {
                        if (object.createTime) {
                            object.createTime = this.parseTime(object.createTime)
                        }
                        this.detail = object
                        console.log(this.detail,'this.detail2');
                    }
                })
            }

        }
        if (this.$route.query.tjid) {
            findTjProfitDetailById({ id: this.$route.query.tjid }).then(res => {
                const { code, message, object } = res
                if (code == 200) {
                    if (object.createTime) {
                        object.createTime = this.parseTime(object.createTime)
                    }
                    this.detail = object
                }
            })
        }
    },
    methods: {
        // 日期格式化
        parseTime(time, pattern) {
            if (arguments.length === 0 || !time) {
                return null
            }
            const format = pattern || '{y}-{m}-{d} {h}:{i}:{s}'
            let date
            if (typeof time === 'object') {
                date = time
            } else {
                if (typeof time === 'string' && /^[0-9]+$/.test(time)) {
                    time = parseInt(time)
                } else if (typeof time === 'string') {
                    time = time.replace(new RegExp(/-/gm), '/')
                }
                if (typeof time === 'number' && time.toString().length === 10) {
                    time = time * 1000
                }
                date = new Date(time)
            }
            const formatObj = {
                y: date.getFullYear(),
                m: date.getMonth() + 1,
                d: date.getDate(),
                h: date.getHours(),
                i: date.getMinutes(),
                s: date.getSeconds(),
                a: date.getDay()
            }
            const time_str = format.replace(/{(y|m|d|h|i|s|a)+}/g, (result, key) => {
                let value = formatObj[key]
                // Note: getDay() returns 0 on Sunday
                if (key === 'a') {
                    return ['日', '一', '二', '三', '四', '五', '六'][value]
                }
                if (result.length > 0 && value < 10) {
                    value = '0' + value
                }
                return value || 0
            })
            return time_str
        }
    }
}
</script>

<style lang="scss" scoped>
.box {
    height: 10px;
}
</style>
